﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SYS.Web.Models;
using SYS.Web.config;
using System.Web.Mvc;
namespace SYS.Web
{
    public static class siteConfig
    {
        /// <summary>
        /// 当前网址
        /// </summary>
        public static string CurrentHost
        {
            get
            {
                return HttpContext.Current.Request.Url.Host;
            }
        }
        public static string Extension = CurrentSite.UrlExtension;

        /// <summary>
        /// 当前网站配置
        /// </summary>
        /// <returns></returns>
        public static Site CurrentSite
        {
            get { return GetFromCode(); }
        }
        private static Site GetFromCode() {
           return new SiteList().GetSite(CurrentHost);
        }
        public static void RegSkin()
        {
            RegSkin(CurrentSite.SiteSkin);
        }
        public static void RegSkin(string skinName)
        {
            RazorViewEngine engine = ViewEngines.Engines.Where(e => e is RazorViewEngine).Single() as RazorViewEngine;
            engine.ViewLocationFormats = engine.PartialViewLocationFormats = engine.MasterLocationFormats = new string[]{
                                        "~/Views/Skins/"+skinName+"/{1}/{0}.cshtml",
                                        "~/Views/Skins/"+skinName+"/{1}/Shared/{0}.cshtml",
                                        //"~/Views/{1}/{0}.cshtml",
                                        "~/Views/Shared/{0}.cshtml",
                                       "~/Views/{0}.cshtml"
            };
        }

        public static List<Site> SiteList { get { return new SiteList().list;}}
    }
}